package board;

import java.io.Serializable;
import java.util.Comparator;
import misc.Vector3i;

public class BoardLocationComparator implements Comparator<BoardLocationWithCost>, Serializable {
    private static final long serialVersionUID = 1L;
    protected Vector3i goal;
    protected int cardinalCost;
    protected int diagonalCost;
    
    @Deprecated
    protected BoardLocationComparator() {}
    
    public BoardLocationComparator(Vector3i goal, int cardinalCost, int diagonalCost) {
        this.goal = goal;
        this.cardinalCost = cardinalCost;
        this.diagonalCost = diagonalCost;
    }
    
    public int compare(BoardLocationWithCost o1, BoardLocationWithCost o2) {
	if(o1.equals(o2))
	    return 0;
        //Below is the heuristic for the pathfinding algorithm
        int estCost1 = o1.getCost() + BoardUtil.costBetween(o1.getBoardLocation(), goal, cardinalCost, diagonalCost);
        int estCost2 = o2.getCost() + BoardUtil.costBetween(o2.getBoardLocation(), goal, cardinalCost, diagonalCost);
	if(estCost1 > estCost2)
	    return 1;
	else
	    return -1;
    }
}
